import request from '@/utils/request'

// 根据年月获取培训列表
export function getTrainingsByYearAndMonth(time) {
  return request({
    url: '/training/training/getTrainingsByYearAndMonth',
    method: 'get',
    params: {
      time: time  // 修改参数名为 'time'
    }
  })
}

// 查询会议管理列表
export function listTrainings(query) {
  return request({
    url: '/training/training/list',
    method: 'get',
    params: query
  })
}

// 查询会议管理详细
export function getTrainings(trainingId) {
  return request({
    url: '/training/training/' + trainingId,
    method: 'get'
  })
}

// 新增会议管理
export function addTrainings(data) {
  return request({
    url: '/training/training',
    method: 'post',
    data: data
  })
}

// 修改会议管理
export function updateTrainings(data) {
  return request({
    url: '/training/training',
    method: 'put',
    data: data
  })
}

// 删除会议管理
export function delTrainings(trainingId) {
  return request({
    url: '/training/training/' + trainingId,
    method: 'delete'
  })
}

// 下载二维码
export function downloadQRCode(id) {
  return request({
    url: '/training/training/qrcode/' + id,
    method: 'get',
    responseType: 'blob' // 重要：设置响应类型为blob以处理文件下载
  })
}
// 导入培训数据
export function importTrainings(data) {
  return request({
    url: '/training/training/importData',
    method: 'post',
    data: data
  })
}
// 导出培训数据
export function exportTrainings(params) {
  return request({
    url: '/training/training/export',
    method: 'post',
    data: params,
    responseType: 'blob'
  })
}

// 导出选中的培训数据
// 导出选中的培训数据
export function exportSelectedTrainings(ids) {  // 直接接收 ids 数组
  return request({
    url: '/training/training/exportSelected',
    method: 'post',
    data: ids,  // 直接传递 ids 数组
    responseType: 'blob'
  })
}

// 下载导入模板
export function importTemplate() {
  return request({
    url: '/training/training/importTemplate',
    method: 'post',
    responseType: 'blob'
  })
}
// 生成订餐模板（添加到文件末尾）
export function generateOrderTemplate(trainingId) {
  return request({
    url: '/training/training/generateOrderTemplate/' + trainingId,
    method: 'get',
    responseType: 'blob'
  })
}
